package com.woniuxy.lifeorder.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.lifeorder.service.entity.BusinessGoods;
import com.woniuxy.lifeorder.service.entity.Orderitem;
import com.woniuxy.lifeorder.service.mapper.BusinessGoodsMapper;
import com.woniuxy.lifeorder.service.mapper.OrderitemMapper;
import com.woniuxy.lifeorder.service.service.OrderitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单项表 服务实现类
 * </p>
 *
 * @author 陈瑜洲，吴继明
 * @since 2020-09-24
 */
@Service
public class OrderitemServiceImpl extends ServiceImpl<OrderitemMapper, Orderitem> implements OrderitemService {

    @Autowired
    private OrderitemMapper orderitemMapper;
    @Autowired
    private BusinessGoodsMapper businessGoodsMapper;
    /**
     * 条件查询 返回订单项 List
     * @param orderitem
     * @return
     */
    @Override
    public List<Orderitem> orderitem_query(Orderitem orderitem) {
        QueryWrapper qw=new QueryWrapper();
        if (orderitem.getFlag()!=null&&orderitem.getFlag().toString().length()<2){
            qw.eq("FLAG",orderitem.getFlag());
        }
        if (orderitem.getOrderId()!=null&&orderitem.getOrderId().toString().length()<10){
            qw.eq("ORDER_ID",orderitem.getGoodsId());
        }
        if (orderitem.getOrderitemId()!=null&&orderitem.getOrderitemId().toString().length()<10){
            qw.eq("ORDERITEM_ID",orderitem.getOrderitemId());
        }
        List<Orderitem> list = orderitemMapper.selectList(qw);
        for (Orderitem o:list) {
            BusinessGoods businessGoods = businessGoodsMapper.selectById(o.getGoodsId());
            o.setBusinessGoods(businessGoods);
        }
        return list;
    }
}
